package com.selfdriving.activity;

import java.util.Calendar;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import com.fourmob.datetimepicker.date.DatePickerDialog;
import com.fourmob.datetimepicker.date.DatePickerDialog.OnDateSetListener;
import com.selfdriving.BaseFragmentActivity;
import com.selfdriving.R;

public class AddTravelTwoActivity extends BaseFragmentActivity implements
		OnClickListener
{
	private ImageView topBack;

	private TextView topText;

	private Button topRight;

	private Button btnStartTime;

	private Button btnEndTime;

	private Calendar calendar = Calendar.getInstance();

	private int mYear;
	private int mMonth;
	private int mDay;

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.add_travel_two);
		initView();
		topRight.setText("发表");
		topText.setText("发表新结伴游");
	}

	public void topBack(View v)
	{
		this.finish();
	}

	private void initView()
	{
		btnStartTime = (Button) findViewById(R.id.btnStartTime);

		btnEndTime = (Button) findViewById(R.id.btnEndTime);

		topBack = (ImageView) findViewById(R.id.topBack);

		topText = (TextView) findViewById(R.id.topText);

		topRight = (Button) findViewById(R.id.topRight);

		btnStartTime.setOnClickListener(this);

		btnEndTime.setOnClickListener(this);
	}

	public void btnStartTime()
	{
		mYear = calendar.get(Calendar.YEAR);
		mMonth = calendar.get(Calendar.MONTH);
		mDay = calendar.get(Calendar.DAY_OF_MONTH);
		DatePickerDialog datePickerDialog = DatePickerDialog.newInstance(
				new OnDateSetListener()
				{

					@Override
					public void onDateSet(DatePickerDialog datePickerDialog,
							int year, int monthOfYear, int dayOfMonth)
					{
						mYear = year;
						mMonth = monthOfYear;
						mDay = dayOfMonth;
						btnStartTime.setText(mYear + "-" + (monthOfYear + 1)
								+ "-" + mDay);
					}
				}, mYear, mMonth, mDay, true, 0);
		datePickerDialog.setVibrate(true);
		datePickerDialog.setYearRange(1985, 2028);
		final String DATEPICKER_TAG = "datepicker";
		datePickerDialog.show(getSupportFragmentManager(), DATEPICKER_TAG);
	}

	public void btnEndTime()
	{
		mYear = calendar.get(Calendar.YEAR);
		mMonth = calendar.get(Calendar.MONTH);
		mDay = calendar.get(Calendar.DAY_OF_MONTH);
		DatePickerDialog datePickerDialog = DatePickerDialog.newInstance(
				new OnDateSetListener()
				{

					@Override
					public void onDateSet(DatePickerDialog datePickerDialog,
							int year, int monthOfYear, int dayOfMonth)
					{
						mYear = year;
						mMonth = monthOfYear;
						mDay = dayOfMonth;
						btnEndTime.setText(mYear + "-" + (monthOfYear + 1)
								+ "-" + mDay);
					}
				}, mYear, mMonth, mDay, true, 0);
		datePickerDialog.setVibrate(true);
		datePickerDialog.setYearRange(1985, 2028);
		final String DATEPICKER_TAG = "datepicker";
		datePickerDialog.show(getSupportFragmentManager(), DATEPICKER_TAG);
	}

	@Override
	public void onClick(View v)
	{
		switch (v.getId())
		{
		case R.id.topBack:
			finish();
			break;
		case R.id.btnStartTime:
			btnStartTime();
			break;

		case R.id.btnEndTime:
			btnEndTime();
			break;

		default:
			break;
		}

	}

	@Override
	protected void initViews()
	{
		// TODO Auto-generated method stub

	}

	@Override
	protected void initEvents()
	{
		// TODO Auto-generated method stub

	}

}
